/**
* @file main.cpp
* @describe 程序入口文件
* @author gaoyuelong
* @date 2022/1/3 
*/

#include "server.h"
#include <unistd.h>

int main(int argc, char **argv)
{
    int iPort = 8888;
    int opt = -1;
    while ((opt = getopt(argc, argv, "dp:")) != -1) {
            switch (opt) {
                case 'd':
                    //守护进程
                    pid_t pid;
                    if (fork() < 0) {
                        perror("fork()");
                    } else if (fork() > 0) {
                        exit(0);
                    }
                    //子进程
                    setsid();
                    close(1);
                    break;
                case 'p':
                    iPort = atoi(optarg);
                    break;
                default:
                    fprintf(stderr, "Usage: %s [-d] [-p] port\n", argv[0]);
                    exit(EXIT_FAILURE);
            }
    }

    EventLoop loop;
    InetAddress addr("10.0.16.11", iPort);
    Server server(&loop, addr, "QoServer");

    server.start();
    loop.loop();
    
    return 0;
}
